//
//  WBNetworkManager+Weather.swift
//  Weibo
//
//  Created by 张俭 on 16/8/19.
//  Copyright © 2016年 张俭. All rights reserved.
//

import Foundation
extension WBNetworkManager {
    func loadWeather( completion:@escaping(_ text:String,_ temperature:String)->()){
        let parameters = ["key":"u6ata2aa8xf5mxcd",
                           "location":"suzhou",
                           "language":"zh-Hans",
                           "unit":"c"]
        WBNetworkManager.shared.get("https://api.thinkpage.cn/v3/weather/now.json", parameters: parameters, progress: nil, success: { (_, data) in
            print(data)
            guard let data = data as? [String:AnyObject],
                let results = data["results"] as? [[String:AnyObject]] , results.count > 0,
                let now = results[0]["now"] as? [String:AnyObject] ,
                let text = now["text"] as? String,
                let temperature = now["temperature"] as? String else{
                completion("","")
                return
            }
            completion(text,temperature)
            }) { (_, error) in
                print(error)
        }
    }
    


}
